﻿CREATE TABLE [dbo].[DefinedAttributes] (
    [AttributeID]         INT            IDENTITY (1000, 1) NOT NULL,
    [EntityType]          NVARCHAR (100) NOT NULL,
    [EntitySubType]       NVARCHAR (100) NULL,
    [AttributeName]       NVARCHAR (255) NOT NULL,
    [Description]         NVARCHAR (MAX) NOT NULL,
    [DataType]            NVARCHAR (50)  NOT NULL,
    [ApprovalRequired]    BIT            CONSTRAINT [DF_DefinedAttributes_ApprovalRequired] DEFAULT ((1)) NOT NULL,
    [FormatType]          NVARCHAR (255) NULL,
    [AttributeLookupName] NVARCHAR (255) NULL,
    CONSTRAINT [PK_DefinedAttributes] PRIMARY KEY CLUSTERED ([AttributeID] ASC),
    CONSTRAINT [FK_DefinedAttributes_DefinedAttributeLookupRules] FOREIGN KEY ([AttributeLookupName]) REFERENCES [dbo].[DefinedAttributeLookupRules] ([AttributeLookupName]),
    CONSTRAINT [FK_DefinedAttributes_DefinedDisplayFormats] FOREIGN KEY ([FormatType]) REFERENCES [dbo].[DefinedDisplayFormats] ([FormatType]),
    CONSTRAINT [FK_DefinedAttributes_DefinedEntitySubTypes] FOREIGN KEY ([EntityType], [EntitySubType]) REFERENCES [dbo].[DefinedEntitySubTypes] ([EntityType], [EntitySubType]),
    CONSTRAINT [FK_DefinedAttributes_EntityTypes] FOREIGN KEY ([EntityType]) REFERENCES [dbo].[DefinedEntityTypes] ([EntityType]) ON UPDATE CASCADE
);




GO
CREATE NONCLUSTERED INDEX [IX_DefinedAttributes]
    ON [dbo].[DefinedAttributes]([AttributeLookupName] ASC);

